package cn.edu.ncu.housinghub.mapper.admin;

import cn.edu.ncu.housinghub.entity.house.PropertyVerification;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AdminHouseMapper {

    //管理员更新房产认证状态
    @Update( "update propertyVerification set verifyStatus = 1 where propertyVerifyId = #{propertyVerifyId}")
    void updatePropertyVerificationStatus(Long propertyVerifyId);

    /**
     * 管理员查询所有房产认证信息
     * @return 房产认证信息列表
     */
    @Select("select propertyVerifyId,userId,propertyNo,propertyPicPath,propertyAddr,verifyStatus,refuseReason,isDeleted,applyTime from propertyVerification where isDeleted = 0")
    List<PropertyVerification> selectAllPropertyVerification();

    /*
    * 批量通过认证
     */
    @Update({"<script>",
            "UPDATE propertyVerification",
            "SET verifyStatus = 1",
            "WHERE propertyVerifyId IN",
            "<foreach item='id' collection='propertyVerifyIds' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    void updateBatchPassVerify(@Param("propertyVerifyIds") List<Long> propertyVerifyIds);


    /*
    * 拒绝认证
     */
    @Update("update propertyVerification set verifyStatus = 2,refuseReason = #{refuseReason} where propertyVerifyId = #{propertyVerifyId}")
    void updatePropertyVerificationReject(@Param("propertyVerifyId") Long propertyVerifyId,@Param("refuseReason") String refuseReason);

}
